#ifndef SYNCCONTROLLER_H
#define SYNCCONTROLLER_H

#include <QObject>
#include "dao/dao.h"
#include "services/genericservice.h"

//#define MAIN_URL "http://impactots.no-ip.org/sync"
//#define MAIN_URL "http://10.1.1.184"
//#define MAIN_URL "http://10.1.1.237:8081/"
//#define MAIN_URL "http://gmtsede.no-ip.info:8081"
#define MAIN_URL "http://192.168.25.2:8081"

class SyncController : public QObject
{
    Q_OBJECT
public:
    explicit SyncController(QObject *parent = 0);
    Q_INVOKABLE void createDB();
    Q_INVOKABLE void startLoad();
    Q_INVOKABLE void startSend();

private:
    template<class T>
    bool importCSV(T *dao, QString response, QString nomeEntidade);
    template<class T>
    bool postCSV(T *daoEntidade, GenericService &genericService, QString nomeEntidade, QString where = QString());
    QString getMacAddress();

signals:
    void loadComplete();
    void loadError();

    void sendComplete();
    void sendError();

public slots:
    void AQEmbalagemProdutoReceived(const QByteArray &response);
    void AQEmbalagemProdutoError(QNetworkReply::NetworkError err);

    void AQEmpresaReceived(const QByteArray &response);
    void AQEmpresaError(QNetworkReply::NetworkError err);

    void AQFornecedorReceived(const QByteArray &response);
    void AQFornecedorError(QNetworkReply::NetworkError err);

    void AQProdEmbalagemReceived(const QByteArray &response);
    void AQProdEmbalagemError(QNetworkReply::NetworkError err);

    void AQProdEmpresaInfoReceived(const QByteArray &response);
    void AQProdEmpresaInfoError(QNetworkReply::NetworkError err);

    void AQProdGrupoReceived(const QByteArray &response);
    void AQProdGrupoError(QNetworkReply::NetworkError err);

    void AQProdutoReceived(const QByteArray &response);
    void AQProdutoError(QNetworkReply::NetworkError err);

    void SSAnotacaoReceived(const QByteArray &response);
    void SSAnotacaoError(QNetworkReply::NetworkError err);

    void SSAnotacaoFotoReceived(const QByteArray &response);
    void SSAnotacaoFotoError(QNetworkReply::NetworkError err);

    void SSNotificacaoReceived(const QByteArray &response);
    void SSNotificacaoError(QNetworkReply::NetworkError err);

    void SSPassosReceived(const QByteArray &response);
    void SSPassosError(QNetworkReply::NetworkError err);

    void SSRastreadorReceived(const QByteArray &response);
    void SSRastreadorError(QNetworkReply::NetworkError err);

    void TRCOLETAReceived(const QByteArray &response);
    void TRCOLETAError(QNetworkReply::NetworkError err);

    void TRCOLETAITEMReceived(const QByteArray &response);
    void TRCOLETAITEMError(QNetworkReply::NetworkError err);

    void TRFORNCOLETAReceived(const QByteArray &response);
    void TRFORNCOLETAError(QNetworkReply::NetworkError err);

    void TRFORNCOLETAITEMReceived(const QByteArray &response);
    void TRFORNCOLETAITEMError(QNetworkReply::NetworkError err);

private:
    Service service;

    GenericService serviceAQEmbalagemProduto;
    GenericService serviceAQEmpresa;
    GenericService serviceAQFornecedor;
    GenericService serviceAQProdEmbalagem;
    GenericService serviceAQProdEmpresaInfo;
    GenericService serviceAQProdGrupo;
    GenericService serviceAQProduto;
    GenericService serviceTRCOLETA;
    GenericService serviceTRCOLETAITEM;
    GenericService serviceTRFORNCOLETA;
    GenericService serviceTRFORNCOLETAITEM;
    GenericService serviceSSAnotacao;
    GenericService serviceSSAnotacaoFoto;
    GenericService serviceSSNotificacao;
    GenericService serviceSSPassos;
    GenericService serviceSSRastreador;
};

#endif // SYNCCONTROLLER_H
